<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>lvmx-express</title>
  <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" />
  <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/5.11.2/css/all.min.css">
  <link rel="stylesheet" href="/stylesheets/style.css">
</head>

<body>
  <nav class="navbar navbar-dark bg-info navbar-expand-lg">
    <a class="navbar-brand" href="/">
      <img src="https://v4.bootcss.com/docs/4.3/assets/brand/bootstrap-solid.svg" width="30" height="30"
        class="d-inline-block align-top" alt="" />
      Bootstrap
    </a>

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item active">
          <a class="nav-link" href="/posts">文章列表</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="/posts/create">文章新增</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="/chat">聊天室</a>
        </li>
      </ul>

      <ul class="navbar-nav">
        <li class="nav-item">
          <a class="nav-link" href="/users/login">Login</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="/users/register">Register</a>
        </li>
      </ul>
    </div>
  </nav>

  <div class="container my-5">
    <ul class="list-group list-group-flush">
      <% for (let i = 0; i < posts.length; i++) { %>
      <li class="list-group-item flex-column align-items-start py-3">
        <div class="d-flex justify-content-between">
          <a class="text-dark w-75" href="/posts/<%= posts[i]._id %>">
            <h4><%= posts[i].title %></h4>
          </a>
          <small class="text-black-50 text-right"><%= dateFormat(posts[i].updatedAt) %></small>
        </div>
        <div class="font-weight-light text-truncate"><%= posts[i].content %></div>
        <div class="mt-2 text-black-50">
          <small><%= posts[i].user && posts[i].user.username %></small>
        </div>
      </li>
      <% } %>
    </ul>

    <nav class="my-5">
      <ul class="pagination justify-content-end">
        <li class="page-item"><a class="page-link" href="#">Previous</a></li>
        <% for (let i = 1; i <= totalPages; i++) { %>
        <li class="page-item <%= pageNum === i ? 'active' : '' %>">
          <a class="page-link" href="/posts?pageNum=<%= i %>"><%= i %></a>
        </li>
        <% } %>
        <li class="page-item"><a class="page-link" href="#">Next</a></li>
      </ul>
    </nav>
  </div>

  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>

</html>